package com.bijava.taskjob;

import com.bijava.annotation.ElasticJob;
import com.bijava.utils.LoggerFactoryUtil;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;

/**
 * 通过自定义注解实现定时任务
 */
@ElasticJob(jobName = "Hello1-Job",jobCron = "0/5 * * * * ?",shardCount = 3,shardItem = "0=A,1=B,2=C")
@Component
public class HelloJob implements SimpleJob {
    private static final Logger log = LoggerFactoryUtil.get();

    @Override
    public void execute(ShardingContext shardingContext) {
        LoggerFactoryUtil.info(log,"当前线程：{}",Thread.currentThread().getId());
        LoggerFactoryUtil.info(log,"任务分片：{}",shardingContext.getShardingTotalCount());
        LoggerFactoryUtil.info(log,"当前分片：{}",shardingContext.getShardingItem());
        LoggerFactoryUtil.info(log,"分片参数：{}",shardingContext.getShardingParameter());
        LoggerFactoryUtil.info(log,"任务参数：{}",shardingContext.getJobParameter());
    }
}